<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2018/8/12
 * Time: 下午2:33
 */
namespace PddWechat\Models\User\Service;

use Dai\Framework\Base\BaseService;
use Dai\Framework\Base\BaseSessionInfo;
use PddWechat\Models\Pddorder\Data\PddOrderData;

class DataCenter extends BaseService
{

    public function __construct()
    {
        $this->pddOrder = new PddOrderData();
    }

    public function execute($basePageInfo)
    {
        /** @var BaseSessionInfo $sessionData */
        $sessionData = $basePageInfo->sessionInfo;
        $uid = $sessionData->uid;
        //获取今日预估收入
        $beginToday = date("Y-m-d H:i:s", mktime(0,0,0,date('m'),date('d'),date('Y')));
        $endToday = date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1);
        $todoyIncome = $this->pddOrder->selectIncome($uid,$beginToday,$endToday);

        //预计本周收入
        $beginWeek = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));
        $endWeek = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
        $weekIncome = $this->pddOrder->selectIncome($uid,$beginWeek,$endWeek);

        //获取本月预估收入
        $beginMonth = date("Y-m-d H:i:s", mktime(0,0,0,date('m'),1,date('Y')));
        $endMonth = date("Y-m-d H:i:s", mktime(23,59,59,date('m'),date('t'),date('Y')));
        $monthIncome = $this->pddOrder->selectIncome($uid,$beginMonth,$endMonth);
        $res = [
            'todayIncome' => floatval($todoyIncome/100),
            'weekIncome' => floatval($weekIncome/100),
            'monthIncome' => floatval($monthIncome/100),
        ];
        return $res;
    }
}